<template>
  <view class="g-content">
    <uni-card
      class="card-course"
      :is-shadow="true"
      v-for="item in list"
      :title="item['申请的课程名']"
      :note="item['申请状态']==1?'未批复':'已批复'"
    >
      <view>申请地点：<span>{{ item['申请的实验室地点'] }}</span></view>
      <view>申请时间：<span>{{ item['上课时间'] }}</span></view>
      <view>课程人数：<span>{{ item['上课人数'] }}</span></view>
      <view v-if="item['申请状态'] == 1">
        <view><uni-easyinput v-model="item['回复']"></uni-easyinput></view>
        <button @click="_accept(item['申请号'], item['回复'])">同意</button>
        <button @click="_refuse(item['申请号'], item['回复'])">拒绝</button>
      </view>
      <view v-else>
        <view>申请回复：<span>{{ item['回复'] }}</span></view>
      </view>
    </uni-card>
    <div style="height: 120rpx;"></div>
    <hans-tabber :list="tab" class="g-tabbar" style="position:fixed;bottom:0;width:100%;left:0;right:0;" :current="1"></hans-tabber>
  </view>
</template>

<script>
  import Adminer from '../../../api/Adminer.js';
  export default {
    data() {
      return {
        uid: this.$store.state.token.id,
        list: [],
        tab: [
          {
          	"text":"实验室",
          	"pagePath":"lab",
          	"iconPath":"../../../static/icon/task.png",
          	"selectedIconPath":"../../../static/icon/task.png"
          },
          {
          	"text":"实验室申请",
          	"pagePath":"apply",
          	"iconPath":"../../../static/icon/task.png",
          	"selectedIconPath":"../../../static/icon/task.png"
          }
        ]
      }
    },
    methods: {
      async _initList(){
        this.Test.log('实验室管理员-申请我的',this.uid);
        const rm = (await Adminer.getApply(this.uid));
        this.Test.log('实验室管理员-申请我的',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('无申请');
            this.list = [];
            return;
          }
          this.list = rm[1].data;
          //this.Toast.show('数据已加载');
        }
      },
      async _accept(id, comment){
        uni.showLoading();
        this.Test.log('实验室管理员-申请接受', id);
        const rm = (await Adminer.replyApply(id, 3, comment));
        this.Test.log('实验室管理员-申请我的',rm);
        uni.hideLoading();
      },
      async _refuse(id, comment){
        uni.showLoading();
        this.Test.log('实验室管理员-申请拒绝', id);
        const rm = (await Adminer.replyApply(id, 2, comment));
        this.Test.log('实验室管理员-申请我的',rm);
        uni.hideLoading();
      }
    },
    onInit() {
      this.uid = this.$store.state.token.id;
    },
    onLoad() {
      this._initList();
    }
  }
</script>

<style>
</style>
